package com.example.video_module.video;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.Observer;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import androidx.viewbinding.ViewBinding;

import com.alibaba.android.arouter.launcher.ARouter;
import com.blankj.utilcode.util.ToastUtils;
import com.example.common.mvvm.view.BaseFragment;
import com.example.video_module.databinding.FragmentInvitationBinding;
import com.example.video_module.video.entity.BeanEntity;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener;

import java.util.List;

public class VideoFragment extends BaseFragment<FragmentInvitationBinding,InvitationViewModel> {

    @Override
    public View bindLayout() {
        return v.getRoot();
    }

    @Override
    public ViewBinding initBinding() {
        FragmentInvitationBinding fragmentInvitationBinding=FragmentInvitationBinding.inflate(inflater);
        return fragmentInvitationBinding;
    }

    @Override
    public void initView() {

    }

    @Override
    public void initData() {
        vm.invitation_list.observe(this, new Observer<List<BeanEntity>>() {
            @Override
            public void onChanged(List<BeanEntity> beanEntities) {
                InvitationAdapter invitationAdapter = new InvitationAdapter();
                v.InvitationRe.setLayoutManager(new LinearLayoutManager(getContext()));
                v.InvitationRe.setAdapter(invitationAdapter);
                invitationAdapter.setNewInstance(vm.invitation_list.getValue());

                v.InvitationSw.setOnRefreshLoadMoreListener(new OnRefreshLoadMoreListener() {
                    @Override
                    public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
                        Toast.makeText(getContext(), "加载", Toast.LENGTH_SHORT).show();
                        v.InvitationSw.finishLoadMore();
                    }

                    @Override
                    public void onRefresh(@NonNull RefreshLayout refreshLayout) {
                        Toast.makeText(getContext(), "刷新", Toast.LENGTH_SHORT).show();
                        v.InvitationSw.finishRefresh();
                    }
                });
            }
        });

    }
}
